package com.learn.springbootcache.controller;

import com.learn.springbootcache.bean.ChinaCity;
import com.learn.springbootcache.bean.ChinaCounty;
import com.learn.springbootcache.bean.ChinaProvince;
import com.learn.springbootcache.bean.ChinaRegion;
import com.learn.springbootcache.service.ChinaProvinceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Jmy
 * @date 2019/10/18 15:20
 * @email jiaomingyu5778@gmail.com
 */
@RestController
public class ChinaProvinceController {

    private static final Logger logger = LoggerFactory.getLogger(ChinaProvinceController.class);

    @Autowired
    ChinaProvinceService chinaProvinceService;

    @GetMapping("/cp")
    public List<ChinaProvince> cpList(){
        return chinaProvinceService.findAllList();
    }

    @GetMapping("/city/{provinceId}")
    public List<ChinaCity> ctiyList(@PathVariable @Valid Integer provinceId){
        return chinaProvinceService.findCityByProvinceId(provinceId);
    }

    @GetMapping("/county/{countyId}")
    public List<ChinaCounty> countyList(@PathVariable @Valid Integer countyId){
        return chinaProvinceService.findCountyByCityId(countyId);
    }

    @GetMapping("/region/{region}")
    public List<ChinaRegion> regionList(@PathVariable @Valid Integer region){
        return chinaProvinceService.findRegionByCountyId(region);
    }

    @GetMapping("/regionById/{id}")
    public ChinaRegion region(@PathVariable @Valid Integer id){
        return chinaProvinceService.findRegionById(id);
    }
}
